<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
*
 */
class SystemsController extends AppController{
    public $name = 'Systems';
	public $layout = 'adminDefault';

    public function index (){
		$systems = $this->System->find('all');
		$this->set(compact('systems'));

    }
    public function addSystems(){
        if($this->data){
            if($this->System->save($this->data))
                $this->Session->SetFlash('Adicionado com sucesso!');
			$this->data = array();
        }
    }
    public function editSystems($id = NULL){
	if($this->data){
	    if($this->System->save($this->data)) {
			$this->Session->SetFlash('Editado com sucesso!');
			$this->redirect(array('controller' => 'systems', 'action' => 'index'));
		}else{
			$this->data = $this->System->read(null,$id);
			}
		}
	}

    public function deleteSystems($id = NULL) {
	    if($id) {
		    if($this->System->delete($id))
			    $this->Session->SetFlash('Deletado com sucesso!');
		    $this->redirect(array('controller' => 'systems', 'action' => 'index'));

	    }
    }

	public function beforeFilter() {
		$user = $this->Auth->user();
		if((!$user['is_admin']) && $this->isAuthorized($this->Auth->user()))
			$this->redirect('/');
	}
}

?>
